//
//  DWSetting.swift
//  DWSwift
//
//  Created by GDL on 2025/6/22.
//

import Foundation
//
//  DWProfile.swift
//  DWSwift
//
//  Created by GDL on 2025/6/20.
//

import Foundation

import SwiftUI
import DWCoreLib
import SwiftfulRouting

struct DWSettingView: View {
    @Binding var userData:String;
    var body: some View {
        VStack(spacing: 0) {
                    // 个人中心内容（非列表）
                    Text("用户名：\(userData)")
                        .font(.title)
                    Button("编辑资料") {
                        print("啥也干不了")
                    }
                    // 其他视图...
                }
                .padding()
                .frame(maxWidth: .infinity,maxHeight: .infinity)
                .background(Color.red)
    }
    
}

struct DWSettingRefresherView: View{
    @Environment(\.router) var router:AnyRouter // 直接访问环境值
    @State var userData = "初始数据" // 个人中心数据
    var body: some View {
        VStack(spacing: 0) {
            CustomNavigationBar(
                title: "设置",
                leftIcon: "arrow.left",
                leftAction:{
                    router.dismissScreen()
                },
                bgColor: .white
            ).statusBar(color: .white)
            
            DWRefresherView {
                DWSettingView(userData: $userData)
            } refresherAction: {completion in
                Task {
                    // 在后台线程延时 3 秒
                    try? await Task.sleep(nanoseconds: 1 * 1_000_000_000)
                    
                    // 切换到主线程执行 UI 更新
                    await MainActor.run {
                        print("3 秒后执行主线程任务")
                        completion()
                        userData = "新数据数据\(Date())" // UI 操作
                    }
                }
            }
        }
    }
}

struct DWSettingRefresherView_Previews: PreviewProvider {
    static var previews: some View {
        DWSettingRefresherView()
    }
}
